<?php
// Call _JCAT_FriendTargetTest::main() if this source file is executed directly.
if (!defined('PHPUnit_MAIN_METHOD'))
	define('PHPUnit_MAIN_METHOD', '_JCAT_FriendTargetTest::main');


require_once 'PHPUnit/Framework.php';

require_once '/home/alee/Project/JeCat/JCAT0.2/trunk/JCAT.Framework_0.2.0/lib.php/Application/Backtrace/class._JCAT_FriendTarget.php';
require_once '/home/alee/Project/JeCat/JCAT0.2/trunk/JCAT.Framework_0.2.0/lib.php/Application/Backtrace/class.JCAT_Backtrace.php';


class aaa
{
	function xxx()
	{
		return BeCalled() ;
	}
	function yyy()
	{
		return BeCalled() ;
	}
	function zzz()
	{
		return BeCalled() ;
	}
	
	function ccc()
	{
		return BeCalled() ;
	}
	
	static $nClassID = 0 ;
}

class bbb
{

	function ooo()
	{
		return BeCalled() ;
	}
	function ppp()
	{
		return BeCalled() ;
	}
	function qqq()
	{
		return BeCalled() ;
	}
	
	function ccc()
	{
		return BeCalled() ;
	}
	
}

function ccc()
{
	return BeCalled() ;
}


aaa::$nClassID = JCAT_Package::RegisterClassID('aaa',6,100) ;


// 被访问者
function BeCalled()
{
	return $aCaller = JCAT_Backtrace::GetCaller() ;
}


/**
 * Test class for _JCAT_FriendTarget.
 * Generated by PHPUnit on 2007-12-20 at 11:59:25.
 */
class _JCAT_FriendTargetTest extends PHPUnit_Framework_TestCase
{
	/**
	 * Runs the test methods of this class.
	 *
	 * @access public
	 * @static
	 */
	public static function main()
	{
		require_once 'PHPUnit/TextUI/TestRunner.php';

		$suite  = new PHPUnit_Framework_TestSuite('_JCAT_FriendTargetTest');
		$result = PHPUnit_TextUI_TestRunner::run($suite);
	}

	/**
	 * Sets up the fixture, for example, opens a network connection.
	 * This method is called before a test is executed.
	 *
	 * @access protected
	 */
	protected function setUp()
	{
	}

	/**
	 * Tears down the fixture, for example, closes a network connection.
	 * This method is called after a test is executed.
	 *
	 * @access protected
	 */
	protected function tearDown()
	{
	}

    /**
     * @todo Implement testPackage().
     */
    public function testPackage() {
        
		$aaa = new aaa() ;
		$bbb = new bbb() ;
		
		
		$aFriendTarget = new _JCAT_FriendTarget( JCAT::PACKAGE_BACKTRACE, '', '' ) ;
		
		// 包内 可用
		$this->assertTrue( $aFriendTarget->IsFriend($aaa->xxx()) ) ;
		$this->assertTrue( $aFriendTarget->IsFriend($aaa->yyy()) ) ;
		$this->assertTrue( $aFriendTarget->IsFriend($aaa->zzz()) ) ;
		$this->assertTrue( $aFriendTarget->IsFriend($aaa->ccc()) ) ;
		
		// 包外 不可用
		$this->assertFalse( $aFriendTarget->IsFriend($bbb->ooo()) ) ;
		$this->assertFalse( $aFriendTarget->IsFriend($bbb->ppp()) ) ;
		$this->assertFalse( $aFriendTarget->IsFriend($bbb->qqq()) ) ;
		$this->assertFalse( $aFriendTarget->IsFriend($bbb->ccc()) ) ;

		$this->assertFalse( $aFriendTarget->IsFriend(ccc()) ) ;
	}

    /**
     * @todo Implement testClass().
     */
    public function testClass() {
        
		$aaa = new aaa() ;
		$bbb = new bbb() ;
		
		
		// 全局函数 函数 ＝＝＝＝＝＝
		$aFriendTarget = new _JCAT_FriendTarget( 0, '', 'ccc' ) ;
		
		// 名为 ccc 的全局函数
		$this->assertTrue( $aFriendTarget->IsFriend(ccc()) ) ;
		
		// 其他函数		
		$this->assertFalse( $aFriendTarget->IsFriend($aaa->xxx()) ) ;
		$this->assertFalse( $aFriendTarget->IsFriend($aaa->yyy()) ) ;
		$this->assertFalse( $aFriendTarget->IsFriend($aaa->zzz()) ) ;	
		$this->assertFalse( $aFriendTarget->IsFriend($aaa->ccc()) ) ;		// 非全局函数，亦不可
		
		$this->assertFalse( $aFriendTarget->IsFriend($bbb->ooo()) ) ;
		$this->assertFalse( $aFriendTarget->IsFriend($bbb->ppp()) ) ;
		$this->assertFalse( $aFriendTarget->IsFriend($bbb->qqq()) ) ;
		$this->assertFalse( $aFriendTarget->IsFriend($bbb->ccc()) ) ;		// 非全局函数，亦不可

		
		
		
		// 类方法  ＝＝＝＝＝＝
		$aFriendTarget = new _JCAT_FriendTarget( 0, 'aaa', 'ccc' ) ;
		
		// 全局函数
		$this->assertFalse( $aFriendTarget->IsFriend(ccc()) ) ;				// 非aaa的ccc，亦不可
		
		// 其他函数		
		$this->assertFalse( $aFriendTarget->IsFriend($aaa->xxx()) ) ;
		$this->assertFalse( $aFriendTarget->IsFriend($aaa->yyy()) ) ;
		$this->assertFalse( $aFriendTarget->IsFriend($aaa->zzz()) ) ;	
		$this->assertTrue( $aFriendTarget->IsFriend($aaa->ccc()) ) ;		// 可用
		
		$this->assertFalse( $aFriendTarget->IsFriend($bbb->ooo()) ) ;
		$this->assertFalse( $aFriendTarget->IsFriend($bbb->ppp()) ) ;
		$this->assertFalse( $aFriendTarget->IsFriend($bbb->qqq()) ) ;
		$this->assertFalse( $aFriendTarget->IsFriend($bbb->ccc()) ) ;		// 非aaa的ccc，亦不可
		
	}
		
		
    /**
     * @todo Implement testFunction().
     */
    public function testFunction() {
	
		$aaa = new aaa() ;
		$bbb = new bbb() ;
		
		
		$aFriendTarget = new _JCAT_FriendTarget( 0, 'bbb', '' ) ;
		
		// 仅 bbb 类 可用
		$this->assertTrue( $aFriendTarget->IsFriend($bbb->ooo()) ) ;
		$this->assertTrue( $aFriendTarget->IsFriend($bbb->ppp()) ) ;
		$this->assertTrue( $aFriendTarget->IsFriend($bbb->qqq()) ) ;
		
		// 非 bbb 类 不可用
		$this->assertFalse( $aFriendTarget->IsFriend($aaa->xxx()) ) ;
		$this->assertFalse( $aFriendTarget->IsFriend($aaa->yyy()) ) ;
		$this->assertFalse( $aFriendTarget->IsFriend($aaa->zzz()) ) ;
		
		$this->assertFalse( $aFriendTarget->IsFriend(ccc()) ) ;
    }
}

// Call _JCAT_FriendTargetTest::main() if this source file is executed directly.
if (PHPUnit_MAIN_METHOD == '_JCAT_FriendTargetTest::main')
	_JCAT_FriendTargetTest::main();
?>
